
function primeFactors(n) {
    let res = [2,3];
    let allNum = 2;
    let flag;
    for (var i = 5; i < n; i++) {
        for (var j = 2; j <= Math.sqrt(i); j++) {
            if (i % j == 0) {
                flag = false;
                break;
            } else {
                flag = true;
            }
        }
        if (flag) {
            res.push(i)
            allNum += 1
        }
    }
    return res
}

let resArr = primeFactors(20)
console.log(resArr)